package com.lblin.tio.packets;

import java.util.concurrent.atomic.AtomicInteger;

import org.tio.core.intf.Packet;

/**
 * 业务消息包结构
 * @author vi
 *
 */
@SuppressWarnings("serial")
public class HelloPacket extends Packet {
	public static final int HEADER_LENGHT = 4;//消息头的长度
	public static final String CHARSET = "utf-8";
	private byte[] body;
	
	public static AtomicInteger synSeqCreator = new AtomicInteger(0);
	
	private static final Object lockObj = new Object();
	
	public HelloPacket(){
		//setSynSeq(gainSynSeq());
	}

	/**
	 * @return the body
	 */
	public byte[] getBody() {
		return body;
	}

	/**
	 * @param body the body to set
	 */
	public void setBody(byte[] body) {
		this.body = body;
	}

	public Integer gainSynSeq() {
		// TODO Auto-generated method stub
		int result = synSeqCreator.incrementAndGet();
		if(result<0){
			synchronized (lockObj) {
				result = synSeqCreator.get();
				if(result<0){
					synSeqCreator.set(1);
					return 1;
				}
				result = synSeqCreator.incrementAndGet();
			}
		}
		return result;
	}
}